package com.sxt.sys.controller;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sxt.springcloud.sys.UserClientService;
import com.sxt.sys.common.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxt.sys.domain.Dept;
import com.sxt.sys.domain.Role;
import com.sxt.sys.domain.User;
import com.sxt.sys.vo.UserVo;

import cn.hutool.core.util.IdUtil;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 老雷
 * @since 2019-09-20
 */
@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserClientService userService;

	
	/**
	 * 用户全查询
	 */
	@RequestMapping("loadAllUser")
	public DataGridView loadAllUser(UserVo userVo) {
		return this.userService.loadAllUser(userVo);

	}
	
	

	/**
	 * 加载最大的排序码
	 * @param
	 * @return
	 */
	@RequestMapping("loadUserMaxOrderNum")
	public Map<String,Object> loadUserMaxOrderNum(){
		return this.userService.loadUserMaxOrderNum();
	}
	
	
	/**
	 * 根据部门ID查询用户
	 */
	@RequestMapping("loadUsersByDeptId")
	public DataGridView loadUsersByDeptId(@RequestParam("deptid") Integer deptid) {
		return this.userService.loadUsersByDeptId(deptid);
	}
	
	
	/**
	 * 把用户名转成拼音
	 */
	@RequestMapping("changeChineseToPinyin")
	public Map<String,Object> changeChineseToPinyin(@RequestParam("username") String username){
		return this.userService.changeChineseToPinyin(username);
	}
	
	/**
	 * 添加用户
	 */
	@RequestMapping("addUser")
	public ResultObj addUser( UserVo userVo) {
		return this.userService.addUser(userVo);
	}

	
	/**
	 * 根据用户ID查询一个用户
	 */
	@RequestMapping("loadUserById")
	public DataGridView loadUserById(@RequestParam("id") Integer id) {
		return this.userService.loadUserById(id);
	}
	
	/**
	 * 修改用户
	 */
	@RequestMapping("updateUser")
	public ResultObj updateUser( UserVo userVo) {
		return this.userService.updateUser(userVo);
	}

	/**
	 * 删除用户
	 */
	@RequestMapping("deleteUser")
	public ResultObj deleteUser(@RequestParam("id") Integer id) {
		return this.userService.deleteUser(id);
	}
	/**
	 * 重置用户密码
	 */
	@RequestMapping("resetPwd")
	public ResultObj resetPwd(@RequestParam("id") Integer id) {
		return this.userService.resetPwd(id);
	}
	
	
	/**
	 * 根据用户ID查询角色并选中已拥有的角色
	 */
	@RequestMapping("initRoleByUserId")
	public DataGridView initRoleByUserId(@RequestParam("id")Integer id) {
		return this.userService.initRoleByUserId(id);
	}
	
	/**
	 * 保存用户和角色的关系
	 */
	@RequestMapping("saveUserRole")
	public ResultObj saveUserRole(@RequestParam("uid")Integer uid,@RequestParam("ids")Integer[] ids) {
		return this.userService.saveUserRole(uid,ids);
	}

	/**
	 * 用户修改密码-旧密码验证
	 */
	@RequestMapping("checkedoldpwd")
	public ResultObj checkedoldpwd(@RequestParam("oldpwd") String oldpwd){
		return this.userService.checkedoldpwd(oldpwd);
	}
	/**
	 * 用户修改密码
	 */
	@RequestMapping("udpatepwd")
	public ResultObj udpatepwd(@RequestParam("newpwd") String newpwd){
		return this.userService.udpatepwd(newpwd);
	}

}

